home *** CD-ROM | disk | FTP | other *** search
- /*
- FILENAME
- OldApp.c
-
- DESCRIPTION
- Contains code for our old-application message overrides.
-
- COPYRIGHT
- Copyright © 1995 Apple Computer, Inc.
- All rights reserved.
-
- Modification history
- 10/04/95 - David Hayward - Version 1.0.4 modified code so that
- the driver can be build under MPW,
- Metrowerks, and Symantec. In general,
- all that was required to do this was
- to add an inline-assembly jumptable
- and to store all globals off of the
- message manager instance context.
- Also made a few changes so that the
- driver can be rebuilt to support any
- resolution by changing the #defines
- kResolution and kPatStretch in
- "CommonDefines.h"
-
- 06/14/95 - Dave Hersey - Version 1.0.3 to fix a bug in
- CustomBufferingAndIO.c when creating
- high-res PICTs, and to make the size
- of buffers more flexible.
-
- 05/26/95 - Dave Hersey - Version 1.0.2 to add the new 'outp'
- desktop printer resource in NewApp.c.
-
- 05/03/95 - Dave Hersey - Version 1.0.1 to fix some minor bugs in
- CustomBufferingAndIO.c.
-
- 01/14/95 - Dave Hersey - Created from the shell of a hollowed-out
- ImageWriter driver.
- */
-
-
- #include <Types.h>
- #include <GXPrinterDrivers.h>
- #include <GXPrinting.h>
-
-
- // Defines used by the old-application compatibility code.
- #define kPortrait (0x04)
- #define kPrintRecordVers (12)
- #define kDriverWDev (0x8800)
-
-
- // Prototypes for local functions.
- OSErr SD_ConvertPrintRecordFrom ( gxUniversalPrintRecordHdl huPrint ) ;
- OSErr SD_ConvertPrintRecordTo ( THPrint hoPrint ) ;
- OSErr SD_PrValidate ( THPrint hPrint, Boolean *wasChanged ) ;
- OSErr UpdatePrintRecord ( THPrint hPrint ) ;
-
-
- /* -----------------------------------------------------------------------
-
- __Startup__ contains our jump table to the overrides.
- This code must be kept in sync with the assembly jump table
- in OldTable.a and the gxOverrideType resource in OldTable.r
-
- ----------------------------------------------------------------------- */
-
- #if defined(__MWERKS__)
- asm void __Startup__(void);
- asm void __Startup__(void)
- {
- DC.L 0 // Reserved for owner count.
-
- JMP SD_ConvertPrintRecordTo // (offset = 4)
- JMP SD_ConvertPrintRecordFrom // (offset = 8)
- JMP SD_PrValidate // (offset = 12)
-
- RTS // this is needed so __Startup__ symbol works
- }
- #endif
-
-
- /* -----------------------------------------------------------------------
-
- SD_ConvertPrintRecordTo is an override of gxConvertPrintRecordTo. It
- takes a print record in old style (driver specific) format, and converts
- it to the format of gxUniversalPrintRecordHdl. Since we don't have an
- "old-style" format we need to support, there's not much we need to do
- here.
-
- ----------------------------------------------------------------------- */
-
- OSErr SD_ConvertPrintRecordTo(THPrint hoPrint)
- {
- TPPrint poPrint; // pointer to old style print record
- gxUniversalPrintRecordHdl huPrint = (gxUniversalPrintRecordHdl) hoPrint; // handle to universal print record
- gxUniversalPrintRecordPtr puPrint; // pointer to universal print record
- short wDev; // cached wDev
-
- puPrint = *huPrint;
- poPrint = *hoPrint;
-
- // We always print at our best resolution, and autofeed at 100% scaling.
-
- puPrint->qualityMode = gxBestQuality;
- puPrint->feed = true;
- puPrint->reduction = 100;
-
- // Save our orientation and copies settings.
- wDev = poPrint->prStl.wDev;
- puPrint->orientation = (wDev & kPortrait)? gxPortraitOrientation: gxLandscapeOrientation;
- puPrint->actualCopies = poPrint->prJob.iCopies;
- puPrint->options = 0;
-
- return noErr;
- }
-
-
- /* -----------------------------------------------------------------------
-
- SD_ConvertPrintRecordFrom is an override for gxConvertPrintRecordFrom.
- It takes a print record in universal format and converts it to old
- style (driver specific) format. Since we don't have an "old-style"
- format we need to support, there's not much we need to do here.
-
- ----------------------------------------------------------------------- */
-
- OSErr SD_ConvertPrintRecordFrom(gxUniversalPrintRecordHdl huPrint)
- {
- gxUniversalPrintRecordPtr puPrint; // pointer to universal print record
- THPrint hoPrint = (THPrint) huPrint; // handle to old style print record
- TPPrint poPrint; // pointer to old style print record
- short wDev; // workspace to create our wDev value
-
- // Cache pointers for size and speed
- puPrint = *huPrint;
- poPrint = *hoPrint;
-
- // Convert various fields of our print record, starting with the wDev.
-
- // This is our base wDev value-- note I was bad and didn't register this
- // with DEVSUPPORT. You should.
-
- wDev = kDriverWDev;
-
- if (puPrint->orientation == gxPortraitOrientation)
- wDev |= kPortrait;
-
- poPrint->prStl.wDev = wDev;
- poPrint->iPrVersion = kPrintRecordVers;
- poPrint->prInfo.iDev = 0;
- poPrint->prInfoPT.iDev = 0;
- poPrint->prStl.bPort = 0;
- poPrint->prStl.feed = false;
- poPrint->prJob.iCopies = puPrint->actualCopies;
- poPrint->prJob.bJDocLoop = 1;
-
- // This routine is so studly, there can be no errors
- return noErr;
- }
-
-
- /* -----------------------------------------------------------------------
-
- SD_PrValidate is an override of gxPrValidate. It validates the current
- print record. It's fairly simplistic--if the wDev or versions don't
- match ours, we call PrintDefault. Otherwise, we call UpdatePrintRecord
- to allow the driver to sanity check any internal fields.
-
- ----------------------------------------------------------------------- */
-
- OSErr SD_PrValidate(THPrint hPrint, // old style print record
- Boolean *wasChanged) // was the print record changed?
- {
- unsigned short wDev;
- Boolean recordIsInvalid = true;
- OSErr anErr = noErr;
-
- // Check the wDev. The upper byte must be equal to our wDev
-
- wDev = (*hPrint)->prStl.wDev;
- wDev >>= 8; // Get just the device ID
-
- // If the device id is equal to ours, check the version number of the print record.
- // Only if that is also equal to the current version, will we return false (valid).
-
- if ((wDev == (kDriverWDev >> 8)) && ((((*hPrint)->iPrVersion) == kPrintRecordVers)))
- recordIsInvalid = false;
-
- // If the print record is not valid, then call PrintDefault so
- // that QuickDraw GX loads our default print record from 'PREC' 0.
- // Otherwise, do the final sanity check/reset of our print record.
-
- if (recordIsInvalid)
- PrintDefault(hPrint);
- else
- anErr = UpdatePrintRecord(hPrint);
-
- *wasChanged = recordIsInvalid;
- return (anErr);
- }
-
-
- /* -----------------------------------------------------------------------
-
- UpdatePrintRecord is called by SD_PrValidate. It simply does a sanity
- check (and reset) of the volatile fields of our old style print records.
-
- ----------------------------------------------------------------------- */
-
- OSErr UpdatePrintRecord(THPrint hPrint)
- {
- OSErr anErr;
- gxUniversalPrintRecordHdl huPrint = (gxUniversalPrintRecordHdl) hPrint;
- gxUniversalPrintRecordPtr puPrint;
-
- // Convert the print record to universal format. If there are
- // no errors, store the resolution, and convert the print
- // record back to non-universal format.
-
- anErr = SD_ConvertPrintRecordTo(hPrint);
-
- if (anErr == noErr)
- {
- puPrint = *huPrint;
-
- // Default the app & device resolutions
- puPrint->devVRes =
- puPrint->devHRes =
- puPrint->appVRes =
- puPrint->appHRes = 72;
-
- // Convert back to non-universal format
- anErr = SD_ConvertPrintRecordFrom((gxUniversalPrintRecordHdl) hPrint);
- }
-
- return anErr;
- }
-